package com.xysoft.framework.interceptor;

import java.lang.reflect.Method;
import java.util.Date;

import org.springframework.aop.AfterReturningAdvice;

import com.xysoft.framework.entity.BusinessEntity;

public class NewEntityInterceptor implements AfterReturningAdvice {

	@Override
	public void afterReturning(Object returnValue, Method method, Object[] args, Object target) throws Throwable {
		if (returnValue instanceof BusinessEntity) {
			BusinessEntity entity = (BusinessEntity) returnValue;
			if (entity.getCreatedDate() == null) {
				entity.setCreatedDate(new Date());
			}
			if (entity.getLastModified() == null) {
				entity.setLastModified(new Date());
			}
			if (entity.getSystemLastModified() == null) {
				entity.setSystemLastModified(new Date());
			}
		}
	}

}
